<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Cropper</title>
  <link rel="stylesheet" href="../assets/css/bootstrap.min.css">
  <link rel="stylesheet" href="../dist/cropper.css">
</head>
<body>

  <div class="container">
    <h1 class="page-header">Crop on canvas with Cropper</h1>
    <div class="row">
      <div class="col-sm-6">
        <h3 class="page-header">Image</h3>
        <div>
          <img class="img-responsive" id="image" src="../assets/img/picture.jpg" alt="Picture">
        </div>
      </div>
      <div class="col-sm-6">
        <h3 class="page-header">Canvas</h3>
        <div>
          <canvas id="canvas"></canvas>
        </div>
      </div>
    </div>
  </div>

  <!-- Scripts -->
  <script src="../assets/js/jquery.min.js"></script>
  <script src="../assets/js/bootstrap.min.js"></script>
  <script src="../dist/cropper.js"></script>
  <script>
    $(function () {
      var $canvas = $('#canvas');
      var $image = $('#image');
      var image = $image[0];

      function start() {
        var width = $(this).width();
        var height = $(this).height();
        var canvas = $canvas[0];
        var cropper;

        canvas.width = width;
        canvas.height = height;
        canvas.getContext('2d').drawImage(
          this,
          0, 0, this.naturalWidth, this.naturalHeight,
          0, 0, width, height
        );

        $canvas.cropper();
      }

      if (image.complete) {
        start.call(image);
      } else {
        $image.one('load', start);
      }
    });
  </script>
</body>
</html>
